package Control;

import Model.User;
import View.SecondMenu;
import View.SecondMenuDirector;
import View.SecondMenuStaff;
import View.SecondMenuVisitor;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class login {

    static Scanner s = new Scanner(System.in);

    //用户名密码登录
    //参数：ArrayList<User> list
    //返回值：User对象
    public static User loginAccount(ArrayList<User> list) {
        System.out.println("请输入您的用户名：");
        String name = s.next();
        System.out.println("请输入您的密码：");
        String code = s.next();
        int i;
        for ( i = 0; i < list.size(); i++) {
            if(name.equals(list.get(i).getName()) && code.equals(list.get(i).getCode())) {
                return list.get(i);
            }
        }
        System.out.println("用户名或密码错误！");
        System.out.println("系统已退出");
        System.exit(0);
        return null;
    }

    //根据权限打开相应二级菜单
    public static void permissionSecondMenu (User u) throws IOException {
        if(u.getId().equals("游客")) {
            SecondMenuVisitor v = new SecondMenuVisitor();
            while(true) {
                SecondMenu.samePage();
                v.differentPage();
                v.visitorOperate(u);//游客菜单显示和操作
            }
        } else if(u.getId().equals("动物饲养员")) {
            SecondMenuStaff s = new SecondMenuStaff();
            while(true) {
                SecondMenu.samePage();
                s.differentPage();
                s.staffOperate(u);//动物饲养员菜单显示和操作
            }
        } else if(u.getId().equals("园长")) {
            SecondMenuDirector d = new SecondMenuDirector();
            SecondMenu.samePage();
            d.differentPage();
            d.directorOperate(u);//园长菜单显示和操作
        }
    }
}